package com.atguigu.gmall.product.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.BaseTrademark;
import com.atguigu.gmall.product.model.CategoryTrademarkVo;
import io.swagger.annotations.Api;
import jdk.internal.dynalink.linker.LinkerServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.atguigu.gmall.product.service.BaseCategoryTrademarkService;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 分类品牌中间表 前端控制器
 *
 * @author atguigu
 * @since 2023-04-18
 */
@Api(tags = "分类品牌中间表控制器")
@RestController
@RequestMapping("/admin/product/") //TODO 填写基础映射URL
public class BaseCategoryTrademarkController {

    @Autowired
    private BaseCategoryTrademarkService baseCategoryTrademarkService;

    /**
     * 根据category3Id获取品牌列表
     *
     * @param category3Id
     * @return
     */
    @GetMapping("baseCategoryTrademark/findTrademarkList/{category3Id}")
    public Result getFindTrademarkListId(@PathVariable("category3Id") Long category3Id) {

        List<BaseTrademark> baseTrademarkList = baseCategoryTrademarkService.getFindTrademarkListId(category3Id);
        return Result.ok(baseTrademarkList);

    }

    /**
     * 根据分类ID查询该分类未关联品牌
     *
     * @param category3Id 三级分类ID
     * @return
     */
    @GetMapping("baseCategoryTrademark/findCurrentTrademarkList/{category3Id}")
    public Result getFindCurrentTrademarkList(@PathVariable("category3Id") Long category3Id) {
        List<BaseTrademark> baseTrademarkList = baseCategoryTrademarkService.getFindCurrentTrademarkList(category3Id);
        return Result.ok(baseTrademarkList);
    }

    /**
     * 保存分类品牌关联
     *
     * @param vo 三级分类编号list 和 品牌id
     * @return
     */
    @PostMapping("baseCategoryTrademark/save")
    public Result save(@RequestBody CategoryTrademarkVo vo) {
        baseCategoryTrademarkService.saveCategoryTrademarkVo(vo);
        return Result.ok();
    }

    /**
     * 删除分类关系
     * @param category3Id
     * @param trademarkId
     * @return
     */
    @DeleteMapping("baseCategoryTrademark/remove/{category3Id}/{trademarkId}")
    public Result delete(@PathVariable("category3Id") Long category3Id, @PathVariable("trademarkId") Long trademarkId) {
        baseCategoryTrademarkService.delete(category3Id, trademarkId);
        return Result.ok();
    }

}
